package com.cssy.yd.logic.web;

import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.util.Region;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.alibaba.fastjson.JSONArray;
import com.byd.acegiext.domain.User;
import com.cssy.authority.entity.ScDepartmentDO;
import com.cssy.authority.service.IScDepartmentService;
import com.cssy.base.web.BaseController;
import com.cssy.base.web.BodyMsg;
import com.cssy.yd.basic.entity.BasicCompanyDO;
import com.cssy.yd.basic.entity.BasicCurrencyDO;
import com.cssy.yd.basic.entity.BasicModeDeliveryDO;
import com.cssy.yd.basic.entity.BasicModePaymentDO;
import com.cssy.yd.basic.service.IBasicCompanyService;
import com.cssy.yd.basic.service.IBasicCurrencyService;
import com.cssy.yd.basic.service.IBasicModeDeliveryService;
import com.cssy.yd.basic.service.IBasicModePaymentService;
import com.cssy.yd.logic.entity.LogicPoDO;
import com.cssy.yd.logic.entity.LogicPoItemDO;
import com.cssy.yd.logic.entity.LogicSoDO;
import com.cssy.yd.logic.entity.LogicSoItemDO;
import com.cssy.yd.logic.service.ILogicSoService;
import com.cssy.yd.logic.service.ILogicSoItemService;
import com.cssy.yd.logic.util.ToRmbUtil;
import com.plat.helper.JqGridHandler;
import com.plat.helper.SearchCondition;
import com.plat.helper.SearchConditions;
import com.plat.helper.SearchResult;
import com.plat.util.GlobalResLoader;
import com.plat.util.OperationFlag;
import com.plat.util.SessionUtil;
import com.plat.util.json.AjaxUtil;
import com.plat.util.json.OutJsonGrid;
/**
 * 销售订单控制器
 * @author huang.xuming [2013-7-9]
 *
 */
@Controller
@RequestMapping("/yd/logic/so")
public class SoController extends BaseController<LogicSoDO> {
	
	private static final Logger logger = Logger.getLogger(SoController.class);

	private static final String MANAGER = "/yd/logic/so/SoManager";// 列表页面
	private static final String EIDT = "/yd/logic/so/SoOperation";// 添加、修改、显示页面
	private static final String MAIN = "/yd/logic/so/SoMain";// //首页流程图

	@Resource(name = "logicSoService")
	ILogicSoService logicSoService;
	@Resource(name = "logicSoItemService")
	ILogicSoItemService logicSoServiceItem;
	@Resource(name = "basicCompanyService")
	IBasicCompanyService basicCompanyService;
	@Resource(name = "basicCurrencyService")
	private IBasicCurrencyService basicCurrencyService;
	@Resource(name="basicModeDeliveryService")
	private IBasicModeDeliveryService basicModeDeliveryService;
	@Resource(name="basicModePaymentService")
	private IBasicModePaymentService basicModePaymentService;
	@Resource(name = "scDepartmentService")
    private IScDepartmentService scDepartmentService;
	

	@Override
	public String manager(HttpServletRequest request, Model model)
			throws Exception {
		return MANAGER;
	}

	@Override
	public void list(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		JqGridHandler hander = new JqGridHandler(request);
		SearchConditions scs = new SearchConditions();
//		scs.setLimitPage(false);//不分页
//		hander.getWheresNotLimit(scs);//不分页的where条件
		hander.getWheres(scs);
		
		SearchResult result = logicSoService.findListByExample(scs);
		OutJsonGrid out = new OutJsonGrid(result);
		out.printJSon(response);

	}

	@Override
	public String operationForm(HttpServletRequest request,
			@PathVariable String id, @PathVariable String flag, Model model)
			throws Exception {
		if (OperationFlag.ADD.equals(flag)) {// 新增加时操作
			
			
			model.addAttribute("flag", "ADD");
			model.addAttribute("userRealName", SessionUtil.getUser(request).getRealName());
		} else {
			LogicSoDO so = logicSoService.findListById(id);
			/*List<LogicSoItemDO> soitem = logicSoServiceItem
					.findItemListBysoId(so.getId());*/
			model.addAttribute("so", so);
			/*model.addAttribute("soitem", soitem);*/
		}
		
		//客户列表
		model.addAttribute("bcList", SoController.getAllClients(basicCompanyService));
		//查询汇率
		model.addAttribute("currency", SoController.getCurrencyList(basicCurrencyService));
		//支付方式
		model.addAttribute("payments",SoController.getPaymentList(basicModePaymentService));
		//交货方式
		model.addAttribute("deliveries",SoController.getDeliveryList(basicModeDeliveryService));
		//部门列表
		model.addAttribute("depts",SoController.getDepartmentList(scDepartmentService));
			
		//用户信息
		User user = SessionUtil.getUser(request);
		model.addAttribute("userRealName", user.getRealName());
		model.addAttribute("userName", user.getName());
				
		return EIDT;
	}
	
	@RequestMapping("/griditems")
	public void griditems(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String id = request.getParameter("id");
		if(StringUtils.isNotBlank(id)){
			LogicSoDO so = logicSoService.findListById(id);
			List<LogicSoItemDO> soitem = logicSoServiceItem.findItemListBysoId(so.getId());
			OutJsonGrid out = new OutJsonGrid(soitem);
			out.printJSon(response);
		}
	}

	@Override
	public Map<String, Object> save(HttpServletRequest request,
			LogicSoDO curAP, BindingResult result, Model model)
			throws Exception {
		BodyMsg bodyMap = BodyMsg.getInstance();
		try {
			String itemdata = request.getParameter("itemdata");
			if (StringUtils.isBlank(itemdata)) {
				bodyMap.isFail();
				bodyMap.configWebInfor("产品列表不能为空！");
				return bodyMap.modelMap;
			}
			logicSoService.soSave(request, curAP);
			bodyMap.isSuccess();
			bodyMap.configWebInfor(GlobalResLoader.getOpsuccess());

		} catch (Exception e) {
			logger.warn(e.getMessage(),e);
			bodyMap.isFail();
			bodyMap.configWebInfor(GlobalResLoader.getOpfailed()
					+ e.getMessage());
		}
		return bodyMap.modelMap;
	}

	@Override
	public Map<String, Object> delete(HttpServletRequest request,
			HttpServletResponse response, Model model) throws Exception {
		BodyMsg bodyMap = BodyMsg.getInstance();
		try {
			String ids = request.getParameter("ids");
			String[] fields = ids.split(",");
			for (String field : fields) {
				LogicSoDO ld = logicSoService.findListById(field);
				ld.setRemoved(1);
				logicSoService.update(ld, SessionUtil.getUser(request));
			}
			bodyMap.isSuccess(GlobalResLoader.getOpsuccess());
			
		} catch (Exception e) {
			logger.warn(e.getMessage(),e);
			bodyMap.isFail(GlobalResLoader.getOpfailed() + e.getMessage());
		}
		return bodyMap.modelMap;
	}
	
	/**
	 * 模块首页
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 * @author huang.xuming [2013-9-3]
	 */
	@RequestMapping("/main")
	public String mainpage(HttpServletRequest request,
			HttpServletResponse response, Model model){
		return MAIN;
	}
	
	@RequestMapping("/getClientBeanByNo")
	public void getClientBeanByNo(HttpServletResponse response,@RequestParam("cliNo") String cliNo){
		BasicCompanyDO dc = getClientBeanByNo( basicCompanyService, cliNo);
		
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("bean", dc);
		AjaxUtil.printJSonArr(response, JSONArray.toJSONString(map));
	}
	//FIXME 获取客户产品的历史报价，ajax实现
	
	/*@RequestMapping("/exportExcel")
	public void exportExcel(HttpServletResponse response,@RequestParam("soid") String soid, SearchConditions scs){
		//TODO 导出功能
		LogicSoDO sodo = logicSoService.findListById(soid);
		List<LogicSoItemDO> sodoitems = logicSoServiceItem.findItemListBysoId(soid);
		
		response.setContentType("text/html;charset=UTF-8");
		response.reset();
		response.setContentType("application/ms-excel");
		String fileNameDisplay = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
		try {
			fileNameDisplay = new String(fileNameDisplay.getBytes("GBK"),
					"iso-8859-1");
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		}
		fileNameDisplay = fileNameDisplay.replace(" ", "%20");
		response.addHeader("Content-Disposition", "attachment;filename="
				+ fileNameDisplay + ".xls");
		OutputStream fout = null;
		
		HSSFWorkbook workbook = new HSSFWorkbook();
		HSSFCellStyle cellStyle = workbook.createCellStyle();
		cellStyle.setBorderBottom((short) 1);
		cellStyle.setBorderLeft((short) 1);
		cellStyle.setBorderRight((short) 1);
		cellStyle.setBorderTop((short) 1);
		cellStyle.setAlignment((short) 2);
		cellStyle.setVerticalAlignment((short) 1l);
		HSSFCellStyle title = workbook.createCellStyle();   
		HSSFFont bold1 = workbook.createFont();
		bold1.setFontName("黑体");
		bold1.setFontHeightInPoints((short)16);
		//bold1.setBoldweight((short) 50);
		title.setFont(bold1);
		title.setAlignment(HSSFCellStyle.ALIGN_CENTER);//左右居中      
		title.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//上下居中   


		
//		int colNum = 0;
		HSSFSheet sheet = workbook.createSheet();
		
		HSSFCell cell = null ;
		HSSFRow row = null ;
		
		row = sheet.createRow(0) ;
		cell = row.createCell(0);
		cell.setCellStyle(title);
		cell.setCellValue(new HSSFRichTextString("送货签收单"));
		//第1行
		row = sheet.createRow(1) ;
		row.setHeight((short)400);
		cell = row.createCell(0);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString("客户订单号："));
		
		cell = row.createCell(1);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString(sodo.getCliOrderNo()));
		
		cell = row.createCell(2);
		cell.setCellStyle(cellStyle);
		
		cell = row.createCell(3);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString("送货编号："));
		
		cell = row.createCell(4);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString(sodo.getNo()));
		cell = row.createCell(5);
		cell.setCellStyle(cellStyle);
		
		//第2行
		row = sheet.createRow(2) ;
		row.setHeight((short)400);
		cell = row.createCell(0);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString("收货单位："));
		
		cell = row.createCell(1);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString(sodo.getShdw()));
		
		cell = row.createCell(2);
		cell.setCellStyle(cellStyle);
		
		cell = row.createCell(3);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString("送货日期："));
		
		cell = row.createCell(4);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString(new SimpleDateFormat("yyyy-MM-dd").format(sodo.getDeliveryDate())));
		cell = row.createCell(5);
		cell.setCellStyle(cellStyle);
		
	
		//第3行
		row = sheet.createRow(3) ;
		row.setHeight((short)400);
		cell = row.createCell(0);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString("送货地址："));
				
		cell = row.createCell(1);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString(sodo.getShdz()));	
		
		for(int j = 2 ; j < 6 ; j++){
			cell = row.createCell(j);
			cell.setCellStyle(cellStyle);
		}
		//第四行
		row = sheet.createRow(4) ;
		row.setHeight((short)400);
		
		cell = row.createCell(0);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString("品名"));
		
		cell = row.createCell(1);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString("品牌"));
		
		cell = row.createCell(2);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString("单位"));
		
		cell = row.createCell(3);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString("数量"));
		
		cell = row.createCell(4);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString("件数"));
		
		cell = row.createCell(5);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString("规格"));
		int i = 0 ;
		for( ; i < sodoitems.size() ; i ++){
			row = sheet.createRow(5 + i) ;
			row.setHeight((short)400);
			cell = row.createCell(0);
			cell.setCellStyle(cellStyle);
			cell.setCellValue(new HSSFRichTextString(sodoitems.get(i).getProdName()));
			
//			cell = row.createCell(1);
//			cell.setCellStyle(cellStyle);
//			cell.setCellValue(new HSSFRichTextString(sodoitems.get(i).getBrand()));
			
			cell = row.createCell(2);
			cell.setCellStyle(cellStyle);
			cell.setCellValue(new HSSFRichTextString(sodoitems.get(i).getProdUnit()));
			
			cell = row.createCell(3);
			cell.setCellStyle(cellStyle);
			cell.setCellValue(new HSSFRichTextString(sodoitems.get(i).getProdQuantity()+""));
			
			cell = row.createCell(4);
			cell.setCellStyle(cellStyle);
			cell.setCellValue(new HSSFRichTextString(sodoitems.get(i).getProdBQuantity()+""));
			
			cell = row.createCell(5);
			cell.setCellStyle(cellStyle);
			cell.setCellValue(new HSSFRichTextString(sodoitems.get(i).getProdSpecDesc()));
		}
		
		row = sheet.createRow(5 + i) ;
		row.setHeight((short)400);
		cell = row.createCell(0);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString("备注："));
		
		for(int j = 1 ; j < 6 ; j++){
			cell = row.createCell(j);
			cell.setCellStyle(cellStyle);
		}
		
		row = sheet.createRow(6 + i) ;
		row.setHeight((short)600);
		cell = row.createCell(0);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString("收货单位及经手人（签章）："));
		for(int j = 1 ; j < 3 ; j++){
			cell = row.createCell(j);
			cell.setCellStyle(cellStyle);
		}		
		cell = row.createCell(3);
		cell.setCellStyle(cellStyle);
		cell.setCellValue(new HSSFRichTextString("送货单位及经手人（签章）："));
		for(int j = 4 ; j < 6 ; j++){
			cell = row.createCell(j);
			cell.setCellStyle(cellStyle);
		}
		
		Region region = new Region((short)1,(short)1,(short)1 ,(short)2);//合并从第rowFrom行columnFrom列  
		Region region1 = new Region((short)1,(short)4,(short)1 ,(short)5);//合并从第rowFrom行columnFrom列  
		Region region2 = new Region((short)2,(short)1,(short)2 ,(short)2);//合并从第rowFrom行columnFrom列  
		Region region3 = new Region((short)2,(short)4,(short)2 ,(short)5);//合并从第rowFrom行columnFrom列  
		Region region4 = new Region((short)3,(short)1,(short)3 ,(short)5);//合并从第rowFrom行columnFrom列  
		Region region5 = new Region((short)(5 + i),(short)1,(short)(5 + i),(short)5);//合并从第rowFrom行columnFrom列  
		Region region6 = new Region((short)0,(short)0,(short)0 ,(short)5);//合并从第rowFrom行columnFrom列  
		Region region7 = new Region((short)(6 + i),(short)0,(short)(6 + i) ,(short)2);//合并从第rowFrom行columnFrom列  
		Region region8 = new Region((short)(6 + i),(short)3,(short)(6 + i) ,(short)5);//合并从第rowFrom行columnFrom列  
		sheet.addMergedRegion(region);// 
		sheet.addMergedRegion(region1);// 
		sheet.addMergedRegion(region2);// 
		sheet.addMergedRegion(region3);// 
		sheet.addMergedRegion(region4);// 
		sheet.addMergedRegion(region5);// 
		sheet.addMergedRegion(region6);// 
		sheet.addMergedRegion(region7);// 
		sheet.addMergedRegion(region8);// 
		sheet.setColumnWidth(0,3000); // 调整第一列宽度 
		try {
			fout = response.getOutputStream();
			workbook.write(response.getOutputStream());
			fout.flush();
			fout.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}*/

	@RequestMapping(value = "/exportExcel")
	public void printer(HttpServletRequest request, HttpServletResponse response) throws Exception{

		try {
			String id = request.getParameter("id");
			LogicSoDO sodo = new LogicSoDO();
			List<LogicSoItemDO> soitem = new ArrayList<LogicSoItemDO>();
			if(!"".equals(id)&&id!=null){
				sodo =logicSoService.findListById(id);
			}
			if(sodo.getId()!=null){
				soitem =logicSoServiceItem.findItemListBysoId(sodo.getId());;
			}
			if(soitem.size()>0){
				request.setAttribute("sodo", sodo);
				request.setAttribute("soitem", soitem);
				request.setAttribute("row", soitem.size());
				request.setAttribute("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
				
				response.setContentType("application/vnd.ms-excel");
				response.setHeader("Content-disposition", "attachment;filename=" + sodo.getNo() + ".xls");
			
				RequestDispatcher dispatcher = request.getRequestDispatcher("/views/printer/SoPrint.jsp");
			
				dispatcher.forward(request, response);
			}
		} catch (ServletException e) {
			e.printStackTrace();
		}
	}
	
//	@RequestMapping(value = "/soprinter")
//	public void deliverprinter(HttpServletRequest request, HttpServletResponse response) throws Exception{

//		try {
//			
//			
//			String id = request.getParameter("id");
//			LogicSoDO so=new LogicSoDO();
//			List<LogicSoItemDO> lp=new ArrayList<LogicSoItemDO>();
//			if(!"".equals(id)&&id!=null){
//				so = logicSoService.findListById(id);
//			
//			}
//			if(so.getId()!=null){
//				lp = logicSoServiceItem.findItemListBysoId(id);
//			}
//			int quan=0;int jquan=0;
	
//			if(lp.size()>0){
//				for(int i=0;i<lp.size();i++){
//					quan+=lp.get(i).getQuantity()==null?0:lp.get(i).getQuantity();
//					jquan+=lp.get(i).getJquantity()==null?0:lp.get(i).getJquantity();
//				}
//				request.setAttribute("so", so);
//				request.setAttribute("lp", lp);
//				request.setAttribute("quan", quan);
//				request.setAttribute("jquan", jquan);
//				response.setContentType("application/vnd.ms-excel");
//				response.setHeader("Content-disposition", "attachment;filename=export_" + System.currentTimeMillis() + ".xls");
//			
//				RequestDispatcher dispatcher = request.getRequestDispatcher("/views/printer/SoPrint.jsp");
//			
//				dispatcher.forward(request, response);
//			}
//		} catch (ServletException e) {
//			e.printStackTrace();
//		}
//	}
	
//	@RequestMapping(value = "/sotprinter")
//	public void sotprinter(HttpServletRequest request, HttpServletResponse response) throws Exception{
//
//		try {
//			
//			
//			String id = request.getParameter("id");
//			LogicSoDO so=new LogicSoDO();
//			List<LogicSoItemDO> lp=new ArrayList<LogicSoItemDO>();
//			if(!"".equals(id)&&id!=null){
//				so = logicSoService.findListById(id);
//			
//			}
//			if(so.getId()!=null){
//				lp = logicSoServiceItem.findItemListBysoId(id);
//			}
////			int quan=0;int jquan=0;
//			if(lp.size()>0){
////				for(int i=0;i<lp.size();i++){
////					quan+=lp.get(i).getQuantity()==null?0:lp.get(i).getQuantity();
////					jquan+=lp.get(i).getJquantity()==null?0:lp.get(i).getJquantity();
////				}
//				request.setAttribute("so", so);
//				request.setAttribute("lp", lp);
//				request.setAttribute("row", lp.size());
//				response.setContentType("application/vnd.ms-excel");
//				response.setHeader("Content-disposition", "attachment;filename=export_" + System.currentTimeMillis() + ".xls");
//			
//				RequestDispatcher dispatcher = request.getRequestDispatcher("/views/printer/SotPrint.jsp");
//			
//				dispatcher.forward(request, response);
//			}
//		} catch (ServletException e) {
//			e.printStackTrace();
//		}
//	}
	
	/////////////////////////////////////////////////////////////
	//TODO 公用
	
	/**
	 * 获取汇率集合
	 * @return
	 */
	public static List<BasicCurrencyDO> getCurrencyList(IBasicCurrencyService basicCurrencyService){
		SearchConditions scs1 = new SearchConditions();
		scs1.setLimitPage(false);
		SearchResult result = basicCurrencyService.findListByExample(scs1);
		
		@SuppressWarnings("unchecked")
		List<BasicCurrencyDO> results= result.getResults();
		return results;
	}
	
	/**
	 * 获取付款方式集合
	 * @param basicModePaymentService
	 * @return
	 */
	public static List<BasicModePaymentDO> getPaymentList(IBasicModePaymentService basicModePaymentService){
		SearchConditions scs3 = new SearchConditions();
		scs3.setLimitPage(false);
		@SuppressWarnings("unchecked")
		List<BasicModePaymentDO> ls = basicModePaymentService.findListByExample(scs3).getResults();
		return ls;
	}
	
	/**
	 * 获取交货方式集合
	 * @param basicModePaymentService
	 * @return
	 */
	public static List<BasicModeDeliveryDO> getDeliveryList(IBasicModeDeliveryService basicModeDeliveryService){
		SearchConditions scs = new SearchConditions();
		scs.setLimitPage(false);
		
		@SuppressWarnings("unchecked")
		List<BasicModeDeliveryDO> ls = basicModeDeliveryService.findListByExample(scs).getResults();
		return  ls;
	}
	
	/**
	 * 获取部门集合
	 * @param scDepartmentService
	 * @return
	 */
	public static List<ScDepartmentDO> getDepartmentList(IScDepartmentService scDepartmentService){
		SearchConditions scs2 = new SearchConditions();
		scs2.setLimitPage(false);
		@SuppressWarnings("unchecked")
		List<ScDepartmentDO> ls = scDepartmentService.findListByExample(scs2).getResults();
		return ls;
	}
	
	/**
	 * 获取全部客户的列表
	 * @param basicCompanyService
	 * @return
	 */
	public static List<BasicCompanyDO> getAllClients(IBasicCompanyService basicCompanyService){
		SearchConditions scs = new SearchConditions();
		scs.addCondition("parentname", "客户", SearchCondition.OP_EQUAL);
		scs.setOrderBy("code");
		scs.setLimitPage(false);//不分页
		return basicCompanyService.find(scs);
	}
	
	/**
	 * 根据编码获取客户信息
	 * @param basicCompanyService
	 * @param cliNo
	 * @return
	 */
	public static BasicCompanyDO getClientBeanByNo(IBasicCompanyService basicCompanyService,String cliNo){
		SearchConditions cs = new SearchConditions();
		cs.addCondition("code", cliNo, SearchCondition.OP_EQUAL);
		List<BasicCompanyDO> ls = basicCompanyService.find(cs);
		if(null == ls || 0 == ls.size()){
			return null;
		}
		return ls.get(0);
	}
}
